package com.cn.yang.dao.impl;

import com.cn.yang.dao.NewsDao;
import com.cn.yang.model.news.NewsClassifyModel;
import com.cn.yang.model.news.NewsModel;
import com.cn.yang.util.GetSqlSession;
import com.cn.yang.util.JDBC;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class NewsDaoImpl implements NewsDao {
    JDBC jdbc = new JDBC();
    //查询 新闻种类
    @Override
    public List<NewsClassifyModel> findClassify() {
        return GetSqlSession.getSqlSession().selectList("com.cn.yang.dao.NewsDao.findClassify");
    }
    //添加新闻
    @Override
    public int addNews(NewsModel model) {
        return GetSqlSession.getSqlSession().insert("com.cn.yang.dao.NewsDao.addNews",model);
    }
    //查询新闻
    @Override
    public List<NewsModel> findNews(NewsModel newsModel) {
        System.out.println("pageNumber"+newsModel.getPageUtil().getPageNumber());
        return GetSqlSession.getSqlSession().selectList("com.cn.yang.dao.NewsDao.findNews",newsModel);
    }
    //查询总条数
    @Override
    public int countNews(NewsModel model) {
        System.out.println("jsjaijfidaf"+model.getPageUtil().getPageNumber());
        System.out.println("jsjaijfidaf"+model.getPageUtil().getPageSize());
        return GetSqlSession.getSqlSession().selectOne("com.cn.yang.dao.NewsDao.countNews",model);
    }
    //查询一条 id ======
    @Override
    public NewsModel selectById(Integer id) {
        GetSqlSession.getSqlSession().update("com.cn.yang.dao.NewsDao.updatevisit",id);
        return GetSqlSession.getSqlSession().selectOne("com.cn.yang.dao.NewsDao.selectById",id);
    }
//更新数据
    @Override
    public int updateNews(NewsModel model) {
        return GetSqlSession.getSqlSession().update("com.cn.yang.dao.NewsDao.updateNews",model);
    }
//删除数据---news
    @Override
    public int deleteById(Integer id) {
        return GetSqlSession.getSqlSession().delete("com.cn.yang.dao.NewsDao.deleteById",id);
    }
}
